/*This Library is an Official Property of The CIDSL Project  and The Author Siddharth Singh ..... And it is Protected by Law
 * in Case its Modification is Been Conducted in a Form Un-authorized by The GNU Foundation and Also The Appropriate Credits are to
 * BE Given to Project if this Library is Being Modified
 * 
 * 
 * Siddharth Singh,
 * Founder,
 * Ahcir Inc.*/
using System;
using Physics;
namespace Physics
{
	/* Changlogs and Daylogs
	 * Date: Wednesday 12:14  May 1 2013
		 * The Day Log :
		 *   I Have Decided The Structure of The Library  , The Struct Entity is The Primary Building Block of The  Project
		 * And The Functions Defined in The Library Would be The Ones That Would Extract The Data..... For More Information on The 
		 * Library Structure Contact Me .....
		 * 
		 * Siddharth Singh 
			*Changelog Date May 3 2013 
			 * The Entity Object Placed in The Top of Object Hiearchy so it would be accessible without the Inclusion of a Class
			 * as it was in before Commit, The Kinematics Section has been Started and Would be Completed First....*/
	public struct entity
		{
		public double? Force;
			public double? Current ;
			public double? ResistanceOfConductor;
		    public double? WorkDoneOnElectricCharge;
			public double? NetElectronCharge;
			public double? NumberOfElectrons;
			public double? CurrentTime;
			public double? InitialVelocity;
		    public double? InitialMomentum;
			public double? FinalVelocity;
		    public double? FinalMomentum;
		    public double? DistanceOfMotion;
		    public double? TimeOfMotion;
			public double? Momentum;
			public double? Velocity;
			public double? Acceleration;
			public double? Mass;
			public double? Weight;
			public double? GravitationalAcceleration;
		    public double? ConductorAreaOfCrossSection;
		    public double? ConductorLenght;
		    public double? ConductorResistance;
		    public double? PotentialDifferenceAcrossTwoEndsOfConductor;
		    public double? Resistivity;
		    public double? MomentOfInertia;
		    public double? DistanceFromAxis;
		    public double? AngularMomentum;
		    public double? CalculateMass;
		public double? AngularVelocity;
		    
		    
		    
	
		
		/*Remember to Put The Double in a Nullable state by putting Double?*/
		 public  double?   CalculateCurrent( )
		{
			if (NetElectronCharge.HasValue == true && CurrentTime.HasValue == true )
			{
			Current = NetElectronCharge / CurrentTime ;
			
			}
			else if ((NetElectronCharge.HasValue == false && NumberOfElectrons.HasValue == true) && CurrentTime.HasValue == true)
			{
				Current = (NumberOfElectrons * (1.6 * 10e-19)) / CurrentTime;
				
			}
			return Current;
		}
			/*Calculation of Final Velocity*/
		public  double? CalculateFinalVelocity( )
		{
			if (TimeOfMotion.HasValue == true && Acceleration .HasValue == true && InitialVelocity.HasValue == true && DistanceOfMotion.HasValue != true)
			{
			  FinalVelocity = InitialVelocity + Acceleration * TimeOfMotion;
				
			}
			else if (Acceleration.HasValue == true && InitialVelocity.HasValue == true && DistanceOfMotion.HasValue == true && TimeOfMotion.HasValue !=true)
			{
				FinalVelocity = 2*Acceleration*DistanceOfMotion+InitialVelocity*InitialVelocity;
				FinalVelocity = (double?)Math.Pow((double)FinalVelocity,0.5) ;
			} 
			return FinalVelocity;
		}
		/*Calculation of Initial Velocity*/
		public  double? CalculateInitialVelocity( )
		{
		if (FinalVelocity.HasValue == true && Acceleration.HasValue == true && TimeOfMotion.HasValue ==true && DistanceOfMotion.HasValue == false)
			{
				InitialVelocity = FinalVelocity - Acceleration * TimeOfMotion;
			 
			} 
			else if (FinalVelocity.HasValue == false && Acceleration.HasValue == true && TimeOfMotion.HasValue ==true && DistanceOfMotion.HasValue == true)
			{
				/*(s - 1/2at*t)/t=u*/
				InitialVelocity = (DistanceOfMotion - 1/2 *Acceleration*TimeOfMotion*TimeOfMotion)/TimeOfMotion;
			}
			else if(FinalVelocity.HasValue == true && Acceleration.HasValue == true && TimeOfMotion.HasValue ==false && DistanceOfMotion.HasValue == true)
			{
				/*2as-v*v=u*u*/
				InitialVelocity = 2*Acceleration*DistanceOfMotion-FinalVelocity*FinalVelocity;
				InitialVelocity = (double?)Math.Pow((double)InitialVelocity,0.5);
			}
			return InitialVelocity;
		}
	/*Calculations of Ohm's Law Relations-Resistance
	 * V/I = R
	 * R = rho * L/A*/	
		public double? CalculateResistanceOfConductor()
		{
			if(PotentialDifferenceAcrossTwoEndsOfConductor.HasValue == true && Current.HasValue == true)
			{
				ResistanceOfConductor = PotentialDifferenceAcrossTwoEndsOfConductor/Current;
				
			}
			if(PotentialDifferenceAcrossTwoEndsOfConductor.HasValue == false && Current.HasValue == false && Resistivity.HasValue == true && ConductorLenght.HasValue == true && ConductorAreaOfCrossSection.HasValue == true)
			{
				ResistanceOfConductor = Resistivity * (ConductorLenght/ConductorAreaOfCrossSection);
				
				
			}
			return ResistanceOfConductor;
		  	
		}
        /*Calculating Resistivity
         * rho = r * (l/a)*/
		public double? CalculateResistivity()
		{
			Resistivity = ResistanceOfConductor * (ConductorLenght/ConductorAreaOfCrossSection);
			return Resistivity;
		}
		/*Ohm's Law Potential Difference Calculation
		 * V = IR */
		public double? CalculatePotentialDifferenceAcrossTwoEndsofConductor()
		{
			PotentialDifferenceAcrossTwoEndsOfConductor = Current * ResistanceOfConductor;
			return PotentialDifferenceAcrossTwoEndsOfConductor;
		}
		/*Calculation for Work Done on a Charge
		 * V = J/Q
		 * VQ = J*/ 
		public double? CalculationWorkDoneOnElectricCharge()
		{
			WorkDoneOnElectricCharge = PotentialDifferenceAcrossTwoEndsOfConductor * NetElectronCharge;
			return WorkDoneOnElectricCharge;
		}
		/*Calculation of Momentum*/
		public double? CalculateMomentum()
		{
		   Momentum = Mass * Velocity;
			return Momentum;
		}
	   public double? CalculateAcceleration()
		{
			if(InitialVelocity.HasValue == true && FinalVelocity.HasValue == true)
			{
				Acceleration = FinalVelocity- InitialVelocity;
			}
			else
			{
				Acceleration = (FinalMomentum-InitialMomentum)/Mass;
			}
			return Acceleration;
		}
		/*Calculation of Force
	     * F = ma*/
		public double? CalculateForce()
		{
			if(Acceleration.HasValue == true)
			{
			Force = Mass * Acceleration;
			}
			else if(Acceleration.HasValue == false)
			{
				Force = FinalMomentum - InitialMomentum;
			}
			return Force;
		}
		 
		/*Calculation of Initial Momentum
		 * f = mv-mu
		 * mu = mv-f*/
		public double? CalculateInitialMomentum()
		{
		if (InitialVelocity.HasValue == true)
			{
			InitialMomentum = Mass * InitialVelocity;
			
			}
			else if(InitialVelocity.HasValue == false)
			{
				InitialMomentum = Mass * CalculateInitialVelocity();
			}
			else if(Force.HasValue == true && FinalMomentum.HasValue == true)
			{
				InitialMomentum = FinalMomentum - Force;
			}
			return InitialMomentum;
		}
	    /*Calculation of Final Momentum
	     * F = MV - MU
	     * F + MU = MV*/
		public double? CalculateFinalMomentum()
		{
			if(FinalVelocity.HasValue == true)
			{
			FinalMomentum = Mass * FinalMomentum;
			}
			else if(FinalVelocity.HasValue == false)
			{
				FinalMomentum = Mass * CalculateFinalVelocity();
			}
			else if (Force.HasValue == true && InitialMomentum.HasValue == true)
			{
				FinalMomentum = Force + InitialMomentum;
			}
			return FinalMomentum;
		}
		/*Calculation of Moment Of Inertia*/ 
		public double? CalculateMomentOfInertia()
		{
			MomentOfInertia = Mass * DistanceFromAxis * DistanceFromAxis;
			return DistanceFromAxis;
		}
		/*Calculation of Angular Velocity*/
		public double? CalculateAngularMomentum()
		{
		   if(MomentOfInertia.HasValue == true && AngularVelocity.HasValue == true)
			{
				AngularMomentum = MomentOfInertia * AngularVelocity;
			}
			if(MomentOfInertia.HasValue == false && Mass.HasValue == true && DistanceFromAxis.HasValue == true)
			{
				AngularMomentum = Mass * AngularVelocity * DistanceFromAxis;
			}
			return AngularMomentum;
		}
		/*Calculating AngularVelocity From Angular Momentum*/
		public double? CalculateAngularVelocityFromAngularMomentum()
		{/*Calculating AngularVelocity From Angular Momentum*/
		if(MomentOfInertia.HasValue == true)
			{
				AngularVelocity = AngularMomentum / MomentOfInertia;
			}
			else
			{
				AngularVelocity = AngularMomentum/(Mass * DistanceFromAxis);
			}
			return AngularVelocity;
		}
	}
}